package net.xuhf.net.xuhf.mqtt;

import net.xuhf.conf.MqttConsumerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/send")
public class ReceiveController {

    @Autowired
    private MqttConsumerConfig config;

    @Value("${spring.mqtt.client.id}")
    private String clientId;

    @GetMapping("/connect")
    @ResponseBody
    public String connect() {
        config.connect();
        return clientId + "链接到服务器";
    }

    @GetMapping("/disConnect")
    @ResponseBody
    public String disConnect() {
        config.disConnect();
        return clientId + "与服务器断开连接";
    }
}
